package com.xx.happychatboot.middleware.rocketmq.strategy.rocketmq;

import com.xx.happychatboot.middleware.netty.domain.enums.RocketMqTypeEnum;
import com.xx.happychatboot.middleware.rocketmq.factory.rocketmq.RocketMqFactory;
import com.xx.happychatboot.middleware.rocketmq.domain.dto.RocketMqCommonDto;
import io.netty.channel.Channel;

import javax.annotation.PostConstruct;

public abstract class AbstractRocketMqStrategy {
    @PostConstruct
    private void init() {
        //将策略类注册进工厂
        RocketMqFactory.register(getStrategyCode().getCode(), this);
    }

    /**
     * 获取策略类型
     * @return
     */
    protected abstract RocketMqTypeEnum getStrategyCode();

    /**
     * 处理消息
     * @param channel
     * @param data
     */
    public abstract void execute(Channel channel, RocketMqCommonDto data);
}
